package org.niux.AutoLoginQQ.timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.niux.AutoLoginQQ.common.Constant;
import org.niux.AutoLoginQQ.ui.Main;

import com.ibm.icu.util.Calendar;

/**
 * 
 * Copyright (c) 2009,niux<br>
 * All rights reserved.<br>
 * 
 * 文件名称：ScanTaskTimer.java<br>
 * 摘    要：监测登录队列的轮循器<br>
 * <br>
 * 当前版本：<br>
 * 作    者：mingxian Email: <a href="mailto:liangmingxian@gmail.com">liangmingxian@gmail.com</a><br>
 * 完成日期：@since 2012-9-12<br>
 * <br>
 * 取代版本：<br>
 * 原作者  ：<br>
 * 完成日期：@since Oct 22, 2009<br>
 */
public class ScanDateTimer extends TimerTask {
	
	private Log log = LogFactory.getLog(this.getClass());
	
//	private Main gui;
	
	public ScanDateTimer(Main gui) {
		super();
//		this.gui = gui;
	}

	@Override
	public void run() {
		log.debug("==========日期轮循器开始监测=============");
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String currentDate = sdf.format(new Date());
		
		Set<String> keySet = Constant.QQ_LIST.keySet();
		
		for(String s : keySet){
			if(Constant.QQ_LIST.get(s).getLoginDate() != null){
				if(!Constant.QQ_LIST.get(s).getLoginDate().equals(currentDate)){
					if(Constant.QQ_LIST.get(s).isLogin()){
						Calendar c = Calendar.getInstance();
						c.add(Calendar.HOUR, 0);
						c.add(Calendar.MINUTE, 0);
						c.add(Calendar.SECOND, 1);
						Constant.QQ_LIST.get(s).setLoginTime(c.getTimeInMillis());
						Constant.QQ_LIST.get(s).setAlreadyLogin((long)0);
					} else {
						Constant.QQ_LIST.get(s).setAlreadyLogin((long)0);
					}
				}
			}
		}
//		log.debug("日期退出队列中有"+ Constant.LOGOUT_QUEEN.size()+"个QQ");
		
//		List<QQNumVO> logoutQueen = new ArrayList<QQNumVO>();
//		
//		logoutQueen.addAll(Constant.LOGOUT_QUEEN);
//		
//		Iterator<QQNumVO> i = logoutQueen.iterator();
//		
//		while (i.hasNext()) {
//			QQNumVO qq = i.next();
//			LoginQQ loginQQ = new LoginQQ(gui);
//			loginQQ.logout(qq.getQqNum(), qq.getLogoutReson());
//			Constant.LOGOUT_QUEEN.remove(qq);
//			i.remove();
//		}
		
//		Constant.LOGOUT_QUEEN.clear();
	}

}
